package de.playmee.enums;

public enum Result {

	// general
	Success					(0, ""),
	Network_Connection		(1, "Cannot connect to the internet. Please check your connection and try again."),
	Database_Connection		(2, "Cannot connect to the Database. Please try again."),
	ParsingException		(3, "Error while retrieving results from database. Please try again."),
	
	// login, register
	Duplicate_Username		(18, "Username already exists. Please try again with another one."),
	Wrong_Username			(30, "Wrong username. Please try again."),
	Wrong_Password			(31, "Wrong password. Please try again."),
	
	// service results
	Process_Done			(40, "Done processing action (no errors)."),
	Process_DoneWithErrors	(41, "Done processing action (with errors)."),
	
	// download from last.fm
	LastFM_TrackNotFound	(50, "Cannot find the track on lastFM."),
	
	// upload to own database
	Rating_Already_Exists	(60, "Rating already exists. You cannot override it.");
	
	private final int code;
	private final String message;
	
	private Result(int code, String message) {
		this.code = code;
		this.message = message;
	}
	
	public int getCode() {
		return code;
	}
	
	public String getMessage() {
		return message;
	}
	
	public static Result getError(int code) {
		for (Result error : Result.values()) {
			if (error.getCode() == code) {
				return error;
			}
		}
		return null;
	}
}
